import os
import sys

from core.rest_client import RestClient
from common.read_data import data

BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(BASE_PATH)

data_file_path = os.path.join(BASE_PATH, "config", "setting.ini")
api_root_url = data.load_ini(data_file_path)["host"]["api_root_url"]


class Field(RestClient):
    '''
    字段的url定义类
    '''

    def __init__(self, api_root_url, **kwargs):
        super(Field, self).__init__(api_root_url, **kwargs)

    def url_preview(self, **kwargs):
        '''
        提取网址参数
        '''
        return self.post("/api/field/url_preview", **kwargs)


    def extract_preview(self, **kwargs):
        '''
        归并字段，预览
        '''
        return self.post("/api/field/extract_preview", **kwargs)

    def merge(self, **kwargs):
        '''
        归并字段
        '''
        return self.post("/api/field/merge", **kwargs)

    def get_length(self, **kwargs):
        '''
        获取长度
        '''
        return self.post("/api/field/get_length", **kwargs)


    def create(self, **kwargs):
        '''
        增加新计算字段
        '''
        return self.post("/api/field/create", **kwargs)

    def modify(self, **kwargs):
        '''
        修改字段
        '''
        return self.post("/api/field/modify", **kwargs)

    def dependency(self, **kwargs):
        '''
        检查字段是否存在依赖关系
        '''
        return self.post("/api/field/dependency", **kwargs)

    def delete(self, **kwargs):
        '''
        删除字段（一般是新增字段）
        '''
        return self.post("/api/field/delete", **kwargs)

field = Field(api_root_url)